package demo;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocketFactory;

public class SSLserver {

	public static void listen() throws Exception {
		int port = 4430;

		ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();
		ServerSocket ssocket = ssocketFactory.createServerSocket(port);

		// Listen for connections
		System.out.println("Listening...");
		Socket socket = ssocket.accept();

		// Create streams to securely send and receive data to the client
		InputStream in = socket.getInputStream();
		BufferedReader reader = new BufferedReader(new InputStreamReader(in));
		String line;
		while ((line = reader.readLine()) != null) {
			System.out.println(line);
		}

		OutputStream out = socket.getOutputStream();

		// Close the socket
		in.close();
		out.close();

	}

	public static void main(String[] args) throws Exception {
		listen();

	}

}
